﻿using System;
using System.ComponentModel;
using System.Runtime.CompilerServices;
using System.Windows;
using LiveCharts.Definitions.Points;
using LiveCharts.Definitions.Series;
using LiveCharts.Wpf.Geometries;
using LiveCharts.SeriesAlgorithms;
using LiveCharts.Wpf;

namespace LiveCharts.Wpf
{
	public class GScatterSeries : GearedSeries, ISeriesView, IScatterSeriesView, IAreaPoint
	{
		public GScatterSeries()
		{
			base.Model = new ScatterAlgorithm(this);
			this.method_2();
		}
		public GScatterSeries(object configuration)
		{
			base.Model = new ScatterAlgorithm(this);
			base.Configuration = configuration;
			this.method_2();
		}

 
		public double MaxPointShapeDiameter
		{
			get
			{
				return (double)base.GetValue(GScatterSeries.MaxPointShapeDiameterProperty);
			}
			set
			{
				base.SetValue(GScatterSeries.MaxPointShapeDiameterProperty, value);
			}
		}

	 
		public double MinPointShapeDiameter
		{
			get
			{
				return (double)base.GetValue(GScatterSeries.MinPointShapeDiameterProperty);
			}
			set
			{
				base.SetValue(GScatterSeries.MinPointShapeDiameterProperty, value);
			}
		}

 
		public GeometryShape GearedPointGeometry
		{
			get
			{
				return (GeometryShape)base.GetValue(GScatterSeries.GearedPointGeometryProperty);
			}
			set
			{
				base.SetValue(GScatterSeries.GearedPointGeometryProperty, value);
			}
		}

		public override IChartPointView GetPointView(ChartPoint point, string label)
		{
			ChartPointView @class = (ChartPointView)point.View;
			if (@class == null)
			{
				ChartPointView class2 = new ChartPointView();
				class2.IsNew = true;
				class2.geometryShape=((GeometryShape)Activator.CreateInstance(this.GearedPointGeometry.GetType()));
				@class = class2;
			}
			else
			{
				@class.IsNew = false;
				point.SeriesView.Model.Chart.View.EnsureElementBelongsToCurrentDrawMargin(@class.DataLabel);
			}
			if (base.DataLabels && @class.DataLabel == null)
			{
				@class.DataLabel = (@class.DataLabel = base.UpdateLabelContent(new DataLabelViewModel
				{
					FormattedText = label,
					Point = point
				}, @class.DataLabel));
			}
			if (!base.DataLabels && @class.DataLabel != null)
			{
				base.Model.Chart.View.RemoveFromDrawMargin(@class.DataLabel);
				@class.DataLabel = null;
			}
			return @class;
		}

		private void method_2()
		{
			base.SetCurrentValue(Series.StrokeThicknessProperty, 0.0);
			base.SetCurrentValue(GScatterSeries.MaxPointShapeDiameterProperty, 15.0);
			base.SetCurrentValue(GScatterSeries.MinPointShapeDiameterProperty, 10.0);
			Func<ChartPoint, string> value = chartPoint_0=>base.Model.CurrentXAxis.GetFormatter()(chartPoint_0.X) + ", " + base.Model.CurrentYAxis.GetFormatter()(chartPoint_0.Y);
			base.SetCurrentValue(Series.LabelPointProperty, value);
			base.DefaultFillOpacity = 0.7;
			
		}

		public double GetPointDiameter()
		{
            return this.MaxPointShapeDiameter / 2.0;
        }


		public static readonly DependencyProperty MaxPointShapeDiameterProperty = DependencyProperty.Register("MaxPointShapeDiameter", typeof(double), typeof(GScatterSeries), new PropertyMetadata(0.0, Series.CallChartUpdater(false)));

		public static readonly DependencyProperty MinPointShapeDiameterProperty = DependencyProperty.Register("MinPointShapeDiameter", typeof(double), typeof(GScatterSeries), new PropertyMetadata(0.0, Series.CallChartUpdater(false)));

		public static readonly DependencyProperty GearedPointGeometryProperty = DependencyProperty.Register("GearedPointGeometry", typeof(GeometryShape), typeof(GScatterSeries), new PropertyMetadata(GearedGeometries.Circle, Series.CallChartUpdater(false)));
	}
}
